#encoding:gbk
__author__ = 'administrator'
import os

import sys
import MySQLdb
reload(sys)
sys.setdefaultencoding('gbk')

if __name__ == '__main__':
    conn = MySQLdb.connect(host = "192.168.15.7", user ="mars",passwd = "mars123",db="", port=3306, charset="utf8")
    cur = conn.cursor()
    conn2 = MySQLdb.connect(host = "192.168.15.7", user ="mars",passwd = "mars123",db="", port=3306, charset="utf8")
    cur2 = conn2.cursor()
    cur3=conn2.cursor()
    conn.select_db('test')
    conn2.select_db('test')
    count6=0
    count7=0
    count8=0
    countflag=0
    count = cur.execute('select * from tmp548 limit 3920  ')
    sql1="SELECT * from yy_line_daily_0408b where work_date=%s and line_name = %s and daily_type=1"
    #sql3="update  yy_line_daily set KILOMETER=%s,KILOMETER_EMPTY='0', KILOMETER_DIESEL=%s,KILOMETER_TROLLEYBUS=%s,KILOMETER_ELECTRIC=%s,ENERGY_CONSUMPTION_DIESEL=%s,ENERGY_CONSUMPTION_ELECTRIC=%s where work_date=%s and LINE_NAME=%s"
    print count

    result = cur.fetchall()
    for r in result:
        #print r[0], r[1] ,r[11],r[12],r[34],r[16],r[36]
        count2=cur2.execute(sql1,(r[1],r[0]))
        #print count2
        result2 = cur2.fetchall()
        if count2 ==0:
            print r[0], r[1] ,r[11],r[12],r[34],r[16],r[36]
            print 'not found this---------------'
        for r2 in result2:
            if count2==1:
                #print r2[5],r2[3],r2[12],r2[13],r2[14],r2[17],r2[18]
                testvar=float(r[11])+float(r[12])+float(r[34])
                testvar2=float(r2[12])+float(r2[13])+float(r2[14])
                if testvar-testvar2 <> 0:
                    print r[0]
                    print testvar
                    print testvar2
            else:
                if countflag == 0:
                    testvar=float(r[11])+float(r[12])+float(r[34])
                    testvar2=float(r2[12])+float(r2[13])+float(r2[14])
                    if testvar-testvar2 <> 0:
                        print r[0]
                        #print testvar
                        #print testvar2
                    countflag = 1
            testvar=0
            testvar2=0
            count6=count6+float(r2[10])
        count7=count7+float(r[11])+float(r[12])+float(r[34])
        #if abs(count7 - count6) > 0.0001:
            #print 'found'
        countflag = 0
    print count6
    print count7
    conn.commit()
    cur.close()
    conn.close()
    conn2.commit()
    cur2.close()
    conn2.close()